import actionTypes from '../actions/actionTypes'
// import Storage from '../../utils/storage'

// let authToken
// Storage.get('authToken').then(value => {
//   authToken = value != null ? true : false;
// })
// let userInfo
// Storage.get('userInfo').then(value => {
//   userInfo = value != null ? value : null;
// })

// (async () => {
//   userInfo = await Storage.get('userInfo')
//   console.log('userInfo', userInfo)
// })()

// console.log('userInfo', userInfo)
const initState = {
  // ...userInfo,
  isLogin: false,
  isLoading: false
}

export default (state = initState, action) => {
  // console.log(action.type, action)
  switch (action.type) {
    case actionTypes.START_LOGIN:
      return {
        ...state,
        isLogin: false,
        isLoading: true
      }
    case actionTypes.LOGIN_SUCCESS:
      console.log('aaaction', {
        ...state,
        ...action.payload,
        isLoading: false,
        isLogin: true,
      })
      return {
        ...state,
        ...action.payload,
        isLoading: false,
        isLogin: true,
      }
    case actionTypes.LOGIN_FAILED:
      return {
        isLogin: false,
        isLoading: false
      }
    default:
      return state;
  }
}